/****************************************************************************
**                                                                         **
**                         Util module for PSSDK                           **
**            Copyright (c) 1997 - 2006 microOLAP Technologies LTD,        **
**                       Khalturin A.P., Naumov D.A.                       **
**                              Source File                                **
**                                                                         **
****************************************************************************/

//---------------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------------
#include "HNErr.h"
#include "HNUtil.h"
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
// HNGetErrorBox
//---------------------------------------------------------------------------
void HNGetErrorBox(DWORD Err)
{
    char *Title = "Warning";
    char *Msg   = "Unknown Error !!!";

    switch(Err)
    {
        //---------------------------------------------------------------------------
        // Common errors
        //---------------------------------------------------------------------------
    case HNERR_OK:   
        Title = "HNERR_OK";
        Msg   = "No errors"; 
        break;
    case HNERR_WRONG_OS:                  
        Title = "HNERR_WRONG_OS";
        Msg   = "Non supported OS version"; 
        break;
    case HNERR_CONFIG_NOT_DEFINED:        
        Title = "HNERR_CONFIG_NOT_DEFINED";
        Msg   = "Adapter config were not defined"; 
        break;
    case HNERR_REG_OPEN_ERROR:            
        Title = "HNERR_REG_OPEN_ERROR";
        Msg   = "Registry key open error"; 
        break;
    case HNERR_ADDR_ERR:                  
        Title = "HNERR_ADDR_ERR";
        Msg   = "Address access error"; 
        break;
    case HNERR_SIZE_ERR:                  
        Title = "HNERR_SIZE_ERR";
        Msg   = "Bad buffer size"; 
        break;
    case HNERR_COUNT_ERR:                 
        Title = "HNERR_COUNT_ERR";
        Msg   = "Bad packets count"; 
        break;
    case HNERR_DRIVER_NOT_LOADED:         
        Title = "HNERR_DRIVER_NOT_LOADED";
        Msg   = "Driver not loaded"; 
        break;
    case HNERR_CONTROL_NOT_OPENED:        
        Title = "HNERR_CONTROL_NOT_OPENED";
        Msg   = "Conrtrol device not opened"; 
        break;
    case HNERR_ADAPTER_NOT_OPENED:        
        Title = "HNERR_ADAPTER_NOT_OPENED";
        Msg   = "No currently opened adapter"; 
        break;
    case HNERR_ADAPTER_ALREADY_OPENED:    
        Title = "HNERR_ADAPTER_ALREADY_OPENED";
        Msg   = "Adapter was opened already"; 
        break;
    case HNERR_ADAPTER_OPEN_ERR:          
        Title = "HNERR_ADAPTER_OPEN_ERR";
        Msg   = "Error opening adapter"; 
        break;
    case HNERR_ADAPTER_REQ_ERR:           
        Title = "HNERR_ADAPTER_REQ_ERR";
        Msg   = "Internal adapter request error"; 
        break;
    case HNERR_ADAPTER_LIST_ERR:          
        Title = "HNERR_ADAPTER_LIST_ERR";
        Msg   = "Internal adapter list error"; 
        break;
    case HNERR_ADAPTER_STATE_ERR:         
        Title = "HNERR_ADAPTER_STATE_ERR";
        Msg   = "Internal adapter state error"; 
        break;
    case HNERR_ADAPTER_THREAD_ERR:        
        Title = "HNERR_ADAPTER_THREAD_ERR";
        Msg   = "Internal adapter thread error"; 
        break;
    case HNERR_ADAPTER_THREAD_COUNT:      
        Title = "HNERR_ADAPTER_THREAD_COUNT";
        Msg   = "Amount of threads of  adapter must less or equal MaxThreadCount"; 
        break;
    case HNERR_MEM_ALLOC_ERROR:           
        Title = "HNERR_MEM_ALLOC_ERROR";
        Msg   = "Memory allocation error"; 
        break;
    case HNERR_INVALID_HANDLE:            
        Title = "HNERR_INVALID_HANDLE";
        Msg   = "Invalid handle"; 
        break;
    case HNERR_MEM_FREE_ERROR:            
        Title = "HNERR_MEM_FREE_ERROR";
        Msg   = "Memory free error"; 
        break;
    case HNERR_CREATE_SYNCOBJ_ERR:        
        Title = "HNERR_CREATE_SYNCOBJ_ERR";
        Msg   = "Error of creating of the system synchronize object"; 
        break;
    case HNERR_THREAD_ERR:                
        Title = "HNERR_THREAD_ERR";
        Msg   = "Internal thread error"; 
        break;
    case HNERR_INCOMPATIBLE_VER:                
        Title = "HNERR_INCOMPATIBLE_VER";
        Msg   = "Incompatible version"; 
        break;

        //---------------------------------------------------------------------------
        // Filter errors
        //---------------------------------------------------------------------------
    case HNERR_FLT_BAD_LEN:               
        Title = "HNERR_FLT_BAD_LEN";
        Msg   = "Bad instructions count in filter programm"; 
        break;
    case HNERR_NO_RET:                    
        Title = "HNERR_NO_RET";
        Msg   = "No return instruction at the end of filter"; 
        break;
    case HNERR_WORK_MEM:                 
        Title = "HNERR_WORK_MEM";
        Msg   = "Wrong index of work memory cell"; 
        break;
    case HNERR_JMP_TO_LONG:            
        Title = "HNERR_JMP_TO_LONG";
        Msg   = "Jump too long"; 
        break;
    case HNERR_WRONG_INSTRUCTION:         
        Title = "HNERR_WRONG_INSTRUCTION";
        Msg   = "Wrong instruction code"; 
        break;
    case HNERR_WRONG_PARAMETER:           
        Title = "HNERR_WRONG_PARAMETER";
        Msg   = "Wrong instruction parameter"; 
        break;
    case HNERR_NO_PROGRAMM:               
        Title = "HNERR_NO_PROGRAMM";
        Msg   = "No progamm in filter"; 
        break;
    case HNERR_LOAD_FILE_ERROR:           
        Title = "HNERR_LOAD_FILE_ERROR";
        Msg   = "No file, bad file (zero len)"; 
        break;
    case HNERR_SAVE_FILE_ERROR:          
        Title = "HNERR_SAVE_FILE_ERROR";
        Msg   = "Can't write to file"; 
        break;
    case HNERR_BUFFER_TOO_SMALL:        
        Title = "HNERR_BUFFER_TOO_SMALL";
        Msg   = "Memory Buffer too small"; 
        break;
    case HNERR_BUFFER_ERROR:             
        Title = "HNERR_BUFFER_ERROR";
        Msg   = "Some error with buffer"; 
        break;

        //---------------------------------------------------------------------------
        // BPF compiler errors
        //---------------------------------------------------------------------------
    case HNERR_BPF_ERROR:       
        Title = "HNERR_BPF_ERROR";
        Msg   = "Syntax error"; 
        break;
    case HNERR_BPF_BAD_SYMBOL:           
        Title = "HNERR_BPF_BAD_SYMBOL";
        Msg   = "Illegal character"; 
        break;
    case HNERR_BPF_UNTERM_COMMENT:        
        Title = "HNERR_BPF_UNTERM_COMMENT";
        Msg   = "Unclosed comment"; 
        break;
    case HNERR_BPF_UNTERM_STRING:        
        Title = "HNERR_BPF_UNTERM_STRING";
        Msg   = "Incomplete line"; 
        break;
    case HNERR_BPF_CANT_OPEN_FILE:       
        Title = "HNERR_BPF_CANT_OPEN_FILE";
        Msg   = "File opening error"; 
        break;
    case HNERR_BPF_DUP_LABEL:             
        Title = "HNERR_BPF_DUP_LABEL";
        Msg   = "Duplicated label"; 
        break;
    case HNERR_BPF_CONST_REDEFINE:        
        Title = "HNERR_BPF_CONST_REDEFINE";
        Msg   = "Redefined constant"; 
        break;
    case HNERR_BPF_DEVIDE_BY_ZERO:        
        Title = "HNERR_BPF_DEVIDE_BY_ZERO";
        Msg   = "Division by zero"; 
        break;
    case HNERR_BPF_BAD_MEM:               
        Title = "HNERR_BPF_BAD_MEM";
        Msg   = "Wrong number of an internal memory cell"; 
        break;
    case HNERR_BPF_BAD_CMD_FMT:         
        Title = "HNERR_BPF_BAD_CMD_FMT";
        Msg   = "Wrong instruction format"; 
        break;
    case HNERR_BPF_BAD_ID_LEN:         
        Title = "HNERR_BPF_BAD_ID_LEN";
        Msg   = "Identifier is too long"; 
        break;
    case HNERR_BPF_BAD_REG:             
        Title = "HNERR_BPF_BAD_REG";
        Msg   = "Wrong register name"; 
        break;
    case HNERR_BPF_BAD_SIZE:           
        Title = "HNERR_BPF_BAD_SIZE";
        Msg   = "Wrong operand size"; 
        break;
    case HNERR_BPF_UNK_LABEL:          
        Title = "HNERR_BPF_UNK_LABEL";
        Msg   = "Unknown label"; 
        break;
    case HNERR_BPF_BACK_LABEL:          
        Title = "HNERR_BPF_BACK_LABEL";
        Msg   = "Label points back"; 
        break;
    case HNERR_BPF_LONG_LABEL:          
        Title = "HNERR_BPF_LONG_LABEL";
        Msg   = "JMP is too long"; 
        break;
    case HNERR_BPF_STR_TOO_LONG:          
        Title = "HNERR_BPF_STR_TOO_LONG";
        Msg   = "String is too long"; 
        break;
    case HNERR_BPF_UNKNOWN_ID:          
        Title = "HNERR_BPF_UNKNOWN_ID";
        Msg   = "Unknown identyfier"; 
        break;
    case HNERR_BPF_COMPILE_ERR:          
        Title = "HNERR_BPF_COMPILE_ERR";
        Msg   = "Compile error"; 
        break;
    }

    ::MessageBox(NULL,Msg,Title,MB_OK | MB_ICONINFORMATION); 
}
